<?

	session_start();
    include_once 'functions_db.php';
	include_once 'functions.php';
	include 'headermenu.php';
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
 "http://www.w3.org/TR/html4/strict.dtd">
<html>
<!-- <link rel="stylesheet" type="text/css" href="default.css"> -->
<link rel="stylesheet" href="yui.css" type="text/css">
<head>
	<title>Methodology Portal</title>
</head>

<body>

<?php   
     //modificare: prin if-ul de mai jos se verifica daca s-a realizat logarea; deasemenea acesta trebuie sa apara in fiecare pagina
	if(ISSET($_SESSION["userId"]) == FALSE)
    {
         echo "<script type =\"text/javascript\">window.location.href=\"methodology.php\";</script>";
		 
		 exit();
	}  
?>


<!-- script dhtml tooltip window
Insert the below code into the <body> section of your page, outside any other tags, especially relatively or absolutely positioned elements -->

<div id="dhtmltooltip"></div>
<script type="text/javascript">
/***********************************************
* Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetxpoint=-60 //Customize x offset of tooltip
var offsetypoint=20 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thecolor, thewidth){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
else if (curX<leftedge)
tipobj.style.left="5px"
else
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetxpoint+"px"

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight)
tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
else
tipobj.style.top=curY+offsetypoint+"px"
tipobj.style.visibility="visible"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip
</script>

<div id="doc" class="yui-t7">
  
   <div id="bd" role="main">
 
 
 <div class="yui-gc">
    <div class="yui-u first">
	<!-- YOUR DATA GOES HERE -->
<h3> Current Projects: </h3>
	
    <form action="" name="testQR" method="post" >
	<div align="right">  <input type="submit" name="add" value="Add project" align="right"> </div>
	</form>
	    </div>
    <div class="yui-u">
	<!-- YOUR DATA GOES HERE -->
	    </div>
 </div>



 <div class="yui-gc">
    <div class="yui-u first" >
 <!-- PRIMUL ECRAN!!! -->
 	

	<?
	$dbh=dbConn();
	//####FUNCTII:
	//####se pare ca daca pun functiile inainte se da refresh la pagina singura!!! si cred ca stiu de ce!
	//####STERGE PROIECT:
	if(isset($_POST['qr_del']))
	{
		//echo ("Proiectul identificat cu numarul ".$_GET[rowid]." a fost sters.");
		mysql_query("delete from projects where id = ".$_GET[rowid].";") or die(mysql_error());
			unset($_GET[rowid]);
		//refreshPage('http://localhost/methodology/');
	}

	//####ADAUGA PROIECT:
	if(isset($_POST['qr_add']))
	{
		if($_POST['name'] != null) {
			
			//calculeaza nr de zile cat dureaza proiectul
			$time = abs (strtotime($_POST['stop_date']) - strtotime($_POST['start_date']))/(60 * 60 * 24);
			//echo ("A fost adaugat un nou proiect.");
			mysql_query("INSERT INTO projects(id, name, description, start_date, stop_date, time, user, edit_date,account) 
			VALUES(null, '".$_POST['name']."', '".$_POST['description']."', '".$_POST['start_date']."', '".$_POST['stop_date']."', $time, '".$_POST['user']."', now(), '".$_SESSION["account"]."'); ") or die(mysql_error());  
				unset($_GET[rowid]);
			//refreshPage('http://localhost/methodology/');
		}
	}

	//####MODIFICA PROIECT:
	if(isset($_POST['qr_update']))
	{
		//calculeaza nr de zile cat dureaza proiectul
			$time = abs (strtotime($_POST['stop_date']) - strtotime($_POST['start_date']))/(60 * 60 * 24);
			
		//echo ("Proiectul identificat cu numarul ".$_GET[rowid]." a fost modificat.");
		mysql_query("update projects set name = '".$_POST['name']."',
			description = '".$_POST['description']."',
			start_date = '".$_POST['start_date']."',
			stop_date = '".$_POST['stop_date']."',
			time = $time,
			user = '".$_POST['user']."',
			edit_date = now()
			where id = ".$_GET[rowid].";") or die(mysql_error());  
			unset($_GET[rowid]);
		//refreshPage('http://localhost/methodology/');
	}




	$result = returnQuery("Select * from projects where account=".$_SESSION["account"].";",$dbh);
	
	//####afisam inregistrarile in tabela:
	while ($row = mysql_fetch_assoc($result)) 
	{
		/////////afisare tabele proiecte
		
		echo "<table width='800' border='1'>";

		echo "<tr bgcolor=#00AFF2>";
		echo "<td colspan='2' width=60%><a href='index.php?rowid=".$row["id"]."' onMouseover=\"ddrivetip('Click on the project name to edit information')\";
 onMouseout=\"hideddrivetip()\">".$row["name"]."</a></td>";
		echo "<td><clr>Start date: </clr>".$row["start_date"]."<br><clr>End date: </clr>".$row["stop_date"]." (".$row["time"].")</td>";
		echo "</tr>";
		echo "<tr>";
		echo "<td width=20%>";
		?>
		<a onMouseover="ddrivetip('Click the icon next to \'Details\' for further project information')";
 onMouseout="hideddrivetip()"> Details </a><a href='project_details.php?rowid= <? echo $row["id"]; ?>'> 
 <img src='images/587px-Icon_Now_Commons_orange.svg.png' width='20' height='17' /> </a> <br>
 
		<a onMouseover="ddrivetip('Click the icon next to \'Stages\' for project stages and documents')";
 onMouseout="hideddrivetip()"> Stages </a><a href='project_stages.php?rowid= <? echo $row["id"]; ?>'>
 <img src='images/600px-Under_construction_icon-blue.svg.png' width='20' height='17' /> </a>  
  <?
		echo "</td>";
		echo "<td colspan='2'><clr>".$row["description"]."</clr></td>";
		echo "</tr>";
		
		echo "<br>";
	
  //echo "<tr><td>User</td><td colspan='2'>".$row["user"]."</td></tr>";
  //echo "<tr><td>Edit date</td><td colspan='2'>".$row["edit_date"]."</td></tr>";
  
      echo "</table>";
	  echo "<br>";
		
		//////////

	}
	
	mysql_free_result($result);	
	?>
	 <br>
     
     
     </div>
    <div class="yui-u">
 <!-- AL DOILEA ECRAN!!! -->
 	<?

	
	
		//####afisam sectiunea add/update/delete:
	if(isset($_POST['add'])) 
	{
		unset($_GET[rowid]);
		display_sect($_GET[0]);
	}
	
	//####Functie pentru selectarea unui proiect:
	if (isset($_GET[rowid])!=0)
	{
		
		display_sect($_GET[rowid]);
	}
	
	//####Functie pt butonul Anulare:
	if(isset($_POST['qr_cancel'])) 
	{
			unset($_GET[rowid]);
		refreshPage('http://localhost/methodology/');
	}
	
	//####Inchidem sesiunea DB:
	dbClose($dbh);
	?>

 
 <br>
     </div>
</div>
 


 </div>
  
</div>
</body>
</html>
<? include 'footer.php';
?>